/*
 * The MIT License (MIT)
 * Copyright © 2022 Walkline Wang (https://walkline.wang)
 * Gitee: https://gitee.com/walkline/ramcu-mechanical-keypad
 */
#ifndef CH9329_H_
#define CH9329_H_

#define ADDR			0x00
#define RETURN_MASK		0x80
#define PACKAGE_LENGTH	6U //命令包长度，不包含数据长度

typedef enum e_ch9329_command
{
	CMD_GET_INFO				= 0x01,
	CMD_SEND_KB_GENERAL_DATA	= 0x02,
	CMD_SEND_KB_MEDIA_DATA		= 0x03,
	CMD_SEND_MS_ABS_DATA		= 0x04,
	CMD_SEND_MS_REL_DATA		= 0x05,
	CMD_SEND_MY_HID_DATA		= 0x06,
	CMD_READ_MY_HID_DATA		= 0x87,
	CMD_GET_PARA_CFG			= 0x08,
	CMD_SET_PARA_CFG			= 0x09,
	CMD_GET_USB_STRING			= 0x0a,
	CMD_SET_USB_STRING			= 0x0b,
	CMD_SET_DEFAULT_CFG			= 0x0c,
	CMD_RESET					= 0x0f
} ch9329_command_t;

typedef struct st_ch9329_chip_info
{
	///0x30: v1.0，0x31:v1.1，类推
	char version[5];

	///0x00: 未连接计算机或未识别
	///0x01: 已连接计算机并识别成功
	uint8_t usb_status;

	///bit0: NUM LOCK 指示灯
	///bit1: CAPS LOCK 指示灯
	///bit2: SCROLL LOCK 指示灯
	///bit3~7: 无效
	uint8_t num_lock_status;
	uint8_t caps_lock_status;
	uint8_t scroll_lock_status;

	uint8_t reserved[5];

} ch9329_chip_info_t;

/**
 * 全局变量
 */
extern ch9329_chip_info_t g_chip_info;

/**
 * 公有函数
 **/
void ch9329_check_status(void);
fsp_err_t ch9329_get_info();
void ch9329_reset(void);
void ch9329_send_kb_data(void);

#endif
